Package money
Class MoneyBag
java.lang.Object
money.Money
money.MoneyBag
A MoneyBag defers exchange rate conversions.
For example adding 12 Swiss Francs to 14 US Dollars is represented
as a bag containing the two Monies 12 CHF and 14 USD. Adding another
10 Swiss francs gives a bag with 22 CHF and 14 USD. Due to the
deferred exchange rate conversion we can later value a MoneyBag with
different exchange rates.
- Author:
- Kent Beck, Robert Duvall (small updates and commenting)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds given money to this money.boolean
int
hashCode()
boolean
isZero()
Tests whether this money is zeromultiply
(int factor) Multiplies this money by the given factor.negate()
Negates this money.static Money
of
(SimpleMoney... monies) Static "constructor" that creates appropriate concrete class based on the given parametersSubtracts given money from this money.toString()
-
Constructor Details
-
MoneyBag
public MoneyBag()Constructs an empty bag of money. -
MoneyBag
Constructs a bag of money from the contents of the given bag of money.
-
-
Method Details
-
of
Static "constructor" that creates appropriate concrete class based on the given parameters- Parameters:
monies
- any number of simple monies to combine
-
add
Description copied from class:Money
Adds given money to this money. -
subtract
Description copied from class:Money
Subtracts given money from this money. -
multiply
Description copied from class:Money
Multiplies this money by the given factor. -
negate
Description copied from class:Money
Negates this money. -
isZero
public boolean isZero()Description copied from class:Money
Tests whether this money is zero -
equals
-
hashCode
public int hashCode() -
toString
-